package com.qdu.bean;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class WeatherBean2 implements WritableComparable<WeatherBean2> {

    private String timestamp;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM dd");

    //空参构造
    public WeatherBean2() {
        this.timestamp = "";
    }

    //序列化
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(timestamp);
    }

    //反序列化
    @Override
    public void readFields(DataInput dataInput) throws IOException {
        timestamp = dataInput.readUTF();
    }


    public String toString() {
        return  timestamp + "\t" ;
    }


    public void set(String timestamp) {
        this.timestamp = timestamp;
    }


    @Override
    public int compareTo(WeatherBean2 o) {
        try {
            long thisValue = sdf.parse(this.timestamp).getTime();
            long thatValue = sdf.parse(o.timestamp).getTime();
            return (thisValue < thatValue ? -1 :(thisValue == thatValue ? 0 : 1));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return -2;
    }
}
